function HandleScoreSheetSearch(gui, user, date, options, data) {
  this._gui = gui;
  this._user = user;
  this._date = date;
  this._options = options;
  this._data = data;
  
  this._popupBox = new ModulePopupBoxSimple();
  
  this._callbackFunc = (options && options.callbackFunc) ? options.callbackFunc : function() {};
  this._search = (options && options.search) ? options.search : null;
  if (!this._search) {
    this._search = PPublishUtils.scoresheetSearch();
  }

  this._cultures = this._data['culture'].data;
  
  this._createElements();
}

HandleScoreSheetSearch.prototype._createElements = function() {
  var _self = this;
  DOMUtils.removeChildElements(this._gui.branch);
  DOMUtils.removeChildElements(this._gui.culture);
  DOMUtils.removeChildElements(this._gui.scoreFrom);
  DOMUtils.removeChildElements(this._gui.scoreTo);

  
  this._gui.branch.options[this._gui.branch.options.length] = new Option('All');
  for (var i = 0, il = Branch.array().length; i < il; i++) {
    var branch = Branch.array()[i];
    option = new Option(branch);
    this._gui.branch.options[this._gui.branch.options.length] = option;
    if (option.text == this._search.branch) {
      this._gui.branch.selectedIndex = this._gui.branch.options.length - 1;
    }
  }
  this._gui.branch.onchange = function() { _self._search.branch = ((this.options[this.selectedIndex].text != 'All') ? this.options[this.selectedIndex].text : ''); };
  
  this._gui.culture.options[this._gui.culture.options.length] = new Option('All');
  for (var i = 0, il = this._cultures.length; i < il; i++) {
    var culture = this._cultures[i];
    option = new Option(culture.name);
    this._gui.culture.options[this._gui.culture.options.length] = option;
    if (option.text == this._search.culture) {
      this._gui.culture.selectedIndex = this._gui.culture.options.length - 1;
    }
  }
  this._gui.culture.onchange = function() { _self._search.culture = ((this.options[this.selectedIndex].text != 'All') ? this.options[this.selectedIndex].text : ''); };
  
  this._gui.scoreFrom.options[this._gui.scoreFrom.options.length] = new Option('-');
  for (var i = 0, il = Score.array().length; i < il; i++) {
    var score = Score.array()[i];
    option = new Option(score);
    this._gui.scoreFrom.options[this._gui.scoreFrom.options.length] = option;
    if (option.text == this._search.scoreFrom) {
      this._gui.scoreFrom.selectedIndex = this._gui.scoreFrom.options.length - 1;
    }
  }
  this._gui.scoreFrom.onchange = function() { _self._search.scoreFrom = ((this.options[this.selectedIndex].text != '-') ? this.options[this.selectedIndex].text : ''); };
  
  this._gui.scoreTo.options[this._gui.scoreTo.options.length] = new Option('-');
  for (var i = 0, il = Score.array().length; i < il; i++) {
    var score = Score.array()[i];
    option = new Option(score);
    this._gui.scoreTo.options[this._gui.scoreTo.options.length] = option;
    if (option.text == this._search.scoreTo) {
      this._gui.scoreTo.selectedIndex = this._gui.scoreTo.options.length - 1;
    }
  }
  this._gui.scoreTo.onchange = function() { _self._search.scoreTo = ((this.options[this.selectedIndex].text != '-') ? this.options[this.selectedIndex].text : ''); };
  
  this._gui.weddingDateFrom.value = (this._search.weddingDateFrom) ? SimpleDate.format(this._search.weddingDateFrom) : '';
  this._gui.weddingDateFrom.onclick = function() { var context = this;
                                                    _self._changeDate.call(_self, this, _self._search.weddingDateFrom, function(sd) { _self._search.weddingDateFrom = sd; context.focus(); }, false);
                                                    return false;
                                                  };
  this._gui.weddingDateFrom.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                                        if (code == 13) {
                                                          _self._callbackFunc(_self._search);
                                                        }
                                                      };
  this._gui.weddingDateTo.value = (this._search.weddingDateTo) ? SimpleDate.format(this._search.weddingDateTo) : '';
  this._gui.weddingDateTo.onclick = function() { var context = this;
                                                  _self._changeDate.call(_self, this, _self._search.weddingDateTo, function(sd) { _self._search.weddingDateTo = sd; context.focus(); }, false);
                                                  return false;
                                                };
  this._gui.weddingDateTo.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                                      if (code == 13) {
                                                        _self._callbackFunc(_self._search);
                                                      }
                                                    };
  
  this._gui.receivedDateFrom.value = (this._search.receivedDateFrom) ? SimpleDate.format(this._search.receivedDateFrom) : '';
  this._gui.receivedDateFrom.onclick = function() { var context = this;
                                                     _self._changeDate.call(_self, this, _self._search.receivedDateFrom, function(sd) { _self._search.receivedDateFrom = sd; context.focus(); }, false);
                                                     return false;
                                                   };
  this._gui.receivedDateFrom.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                                         if (code == 13) {
                                                           _self._callbackFunc(_self._search);
                                                         }
                                                       };
  this._gui.receivedDateTo.value = (this._search.receivedDateTo) ? SimpleDate.format(this._search.receivedDateTo) : '';
  this._gui.receivedDateTo.onclick = function() { var context = this;
                                                 _self._changeDate.call(_self, this, _self._search.receivedDateTo, function(sd) { _self._search.receivedDateTo = sd; context.focus(); }, false);
                                                 return false;
                                               };
  this._gui.receivedDateTo.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                                     if (code == 13) {
                                                       _self._callbackFunc(_self._search);
                                                     }
                                                   };
  this._gui.searchButton.onclick = function() { _self._callbackFunc(_self._search); };
};

HandleScoreSheetSearch.prototype._changeDate = function(label, currentDate, onChangeFunc, showTime) {
  var _self = this;
  this._wContainer = document.createElement('div');
  this._wContainer.style.left = DOMUtils.findPos(label)[0] + 'px';
  this._wContainer.style.top = DOMUtils.findPos(label)[1] + 'px';
  this._popupBox._open(this._wContainer, { pos: DOMUtils.findPos(label) });
  
  var ds = new DateSelect(currentDate, null, { container: this._wContainer, showTime: showTime });
  ds._selectFunc = function(sd) { _self._selectDate.call(_self, sd, label, onChangeFunc, showTime); };
};

HandleScoreSheetSearch.prototype._selectDate = function(sd, label, onChangeFunc, showTime) {
  
  onChangeFunc(sd);
  this._showDate(sd, label, showTime);
  this._popupBox._close();
};

HandleScoreSheetSearch.prototype._showDate = function(sd, label, showTime) {
  if (sd) { 
    label.value = SimpleDate.format(sd, showTime);
  } else {
    label.value = '';
  }
};

HandleScoreSheetSearch.toSql = function(search) {
  var str1 = (search.branch != '') ? '(t.branch =\'' + search.branch + '\')'  : '1 = 1';
  var str2 = (search.culture != '') ? '(t.culture1 = \'' + search.culture + '\' OR t.culture2 = \'' + search.culture + '\')' : '1=1';
  var str3 = (search.scoreFrom != '') ? '(t.score >= \'' + search.scoreFrom + '\')' : '1=1';
  var str4 = (search.scoreTo != '') ? '(t.score <= \'' + search.scoreTo + '\')' : '1=1';

  var str5 = (search.weddingDateFrom) ? '(t.wedding_date >= \'' + SimpleDate.toStamp(search.weddingDateFrom) + '\')' : '1=1';
  var str6 = (search.weddingDateTo) ? '(t.wedding_date <= \'' + SimpleDate.toStamp(search.weddingDateTo) + '\')' : '1=1';
  var str7 = (search.receivedDateFrom) ? '(t.received_date >= \'' + SimpleDate.toStamp(search.receivedDateFrom) + '\')' : '1=1';
  var str8 = (search.receivedDateTo) ? '(t.received_date <= \'' + SimpleDate.toStamp(search.receivedDateTo) + '\')' : '1=1';
  
  return '(' + '(' + str1 + ')' + ' AND ' + '(' + str2 + ')' + ' AND ' + '(' + str3 + ')' + ' AND ' + '(' + str4 + ')' + ' AND ' + '(' + str5 + ')' + ' AND ' + '(' + str6 + ')' + ' AND ' + '(' + str7 + ')' + ' AND ' + '(' + str8 + ')' + ')';
};